//
//  PicturesViewController.m
//  MusicNews
//
//  Created by lanou3g on 15/10/13.
//  Copyright © 2015年 LC.J. All rights reserved.
//

#import "PicturesViewController.h"
#import "RecommendViewController.h"
#import "GroupViewController.h"

@interface PicturesViewController ()
@property(nonatomic,retain)UISegmentedControl *segmentControl;
@property(nonatomic,retain)RecommendViewController *recommendVC;
@property(nonatomic,retain)GroupViewController *groupVC;

@end

@implementation PicturesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"美图";
    
    
    //
    [self.segmentControl addTarget:self action:@selector(changeView:) forControlEvents:UIControlEventValueChanged];
    
    [self addSubViews];
    
}

#pragma mark  添加两个视图
-(void)addSubViews{
    //推荐页面
    _recommendVC = [[RecommendViewController alloc]init];
    [self.view addSubview:_recommendVC.view];
    
    //分类页面
    _groupVC = [[GroupViewController alloc]init];
    [self.view addSubview:_groupVC.view];
    //默认显示推荐页面视图
    [self.view bringSubviewToFront:_recommendVC.view];
    
    [self.view bringSubviewToFront:_segmentControl];
}


#pragma mark  segmentControl方法
-(void)changeView:(UISegmentedControl *)sender{
    switch (sender.selectedSegmentIndex) {
        case 0:
            [self.view bringSubviewToFront:_recommendVC.view];
            break;
        case 1:
            [self.view bringSubviewToFront:_groupVC.view];
            break;
        default:
            break;
    }
    //提前,防止无法点击响应事件
    [self.view bringSubviewToFront:_segmentControl];
}


#pragma mark   懒加载

-(UISegmentedControl *)segmentControl{
    if(!_segmentControl){
        _segmentControl = [[UISegmentedControl alloc]initWithItems:@[@"推荐",@"分类"]];
        _segmentControl.frame = CGRectMake(0, 64, self.view.bounds.size.width, 30);
        
        _segmentControl.userInteractionEnabled = YES;
        _segmentControl.selectedSegmentIndex = 0;
        _segmentControl.tintColor = [UIColor whiteColor];
        NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
        textAttrs[NSForegroundColorAttributeName] = [UIColor colorWithWhite:0.445 alpha:1.0];
        textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:15];
        [_segmentControl setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
        NSMutableDictionary *textAttrs2 = [NSMutableDictionary dictionary];
        textAttrs2[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.380 green:0.815 blue:0.967 alpha:1.000];
        textAttrs2[NSFontAttributeName] = [UIFont systemFontOfSize:15];
        [_segmentControl setTitleTextAttributes:textAttrs2 forState:UIControlStateSelected];
        _segmentControl.backgroundColor = [UIColor whiteColor];
        
        [self.view addSubview:_segmentControl];
    }
    return _segmentControl;
}

//-(RecommendViewController *)recommendVC{
//    if(!_recommendVC){
//        _recommendVC = [[RecommendViewController alloc]init];
//        [self.view addSubview:_recommendVC.view];
//    }
//    return _recommendVC;
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
